<?php

namespace app\admin\controller;

use think\Db;

use think\Request;

use think\Controller;

use app\admin\model\Users as UsersModel;

class Fenxiao extends Common{

    //会员列表

    public function index(){

        if(request()->isPost()){

            $key=input('post.key');
            
            $page =input('pageIndex');

            $pageSize =input('pageSize');
    
            $list=db('users')->alias('u')

                ->join(config('database.prefix').'user_level ul','u.level = ul.level_id','left')

                ->field('u.*,ul.level_name')

                ->where('u.email|u.mobile|u.nickname','like',"%".$key."%")
                ->where('statecheck = 1')

                ->order('u.user_id desc')

                ->paginate(array('list_rows'=>$pageSize,'page'=>$page))

                ->toArray();

            return $result = ['code'=>0,'msg'=>'获取成功!','list'=>$list['data'],'count'=>$list['total'],'rel'=>1];
        }

        return $this->fetch();
    }

    // public function usersState(){

    //     $id=input('post.id');

    //     $status=db('users')->where(array('user_id'=>$id))->value('is_lock');//判断当前状态情况

    //     if($status==1){

    //         $data['is_lock'] = 0;

    //         db('users')->where(array('user_id'=>$id))->setField($data);

    //         $result['info'] = '状态开启';

    //         $result['status'] = 1;

    //     }else{

    //         $data['is_lock'] = 1;

    //         db('users')->where(array('user_id'=>$id))->setField($data);

    //         $result['info'] = '状态禁止';

    //         $result['status'] = 1;

    //     }

    //     return $result;

    // }

    public function getRegion(){

        $Region=db("region");

        $pid = input("pid");

        $arr = explode(':',$pid);

        $map['pid']=$arr[1];

        $list=$Region->where($map)->select();

        return $list;

    }

    //通过审核
    public function usersPass($user_id=''){

        $user = db('users')->where('user_id',$user_id)->find();

        if($user['statecheck']==1){	
        	
        	db('users')->where('user_id',$user_id)->update(['statecheck' => 2]);
			
			 // return ['msg'=>'会员审核通过成功']	;

        }else{

        	// return ['msg'=>'会员审核通过失败'];
        
        }
    
        $this->redirect('index');

    }

    //不通过审核，重新提交
    public function usersNotPass($user_id=''){

        $user = db('users')->where('user_id',$user_id)->find();

        if($user['statecheck']==1){	
        	
        	db('users')->where('user_id',$user_id)->update(['statecheck' => 0]);

        }else{


        
        }
    
        $this->redirect('index');

    }

    // public function delall(){

    //     $map['user_id'] =array('in',input('param.ids'));

    //     db('users')->where($map)->delete();

    //     $result['msg'] = '删除成功！';

    //     $result['url'] = url('index');

    //     return $result;

    // }

     
}